﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace IYAKASAPortal.PrintAll
{
    public partial class PrintConfig : System.Web.UI.Page
    {
       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
             {
              this.BindSelectedAJ();
              this.BindSelectedZJ();
             }           
         }
       protected void btnSave_Click(object sender, EventArgs e)
        {
            UpdateSelectAJ();
            UpdateSelectZJ();
            gfLibrary.gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "保存成功!");
        }
       protected void UpdateSelectAJ()
        {   string ajzpd = "";
            if (rbtnAJZPD.Items[0].Selected == true)
            ajzpd = "1";
            else if (rbtnAJZPD.Items[1].Selected == true)
            ajzpd = "0";
            UpdateValue(ajzpd,"AJ_ZPDZT");
            ajzpd = "";
         

            if (chkAJItems.Items[0].Selected == true)
                ajzpd = "1,";
            if (chkAJItems.Items[1].Selected == true)
                ajzpd += "2,";
            if (chkAJItems.Items[2].Selected == true)
                ajzpd += "0,";
            if (chkAJItems.Items[3].Selected == true)
                ajzpd += "3,";
            UpdateValue(ajzpd, "AJ_ZPD");
            ajzpd = "";


            if (rbtnAJSH.Items[0].Selected == true)
                ajzpd = "1";
            else if (rbtnAJSH.Items[1].Selected == true)
                ajzpd = "0";
            UpdateValue(ajzpd, "AJ_SHZT");
            ajzpd = "";


            if (rbtnAJItem.Items[0].Selected == true)
                ajzpd = "1";
            else if (rbtnAJItem.Items[1].Selected == true)
                ajzpd = "0";
            UpdateValue(ajzpd, "AJ_SH");
            ajzpd = "";
        }
       protected void UpdateSelectZJ()
        {
            string ajzpd = "";
            if (rbtnZJZPD.Items[0].Selected == true)
                ajzpd = "1";
            else if (rbtnZJZPD.Items[1].Selected == true)
                ajzpd = "0";
            UpdateValue(ajzpd, "ZJ_ZPDZT");
            ajzpd = "";


            if (chkZJItems.Items[0].Selected == true)
                ajzpd = "1,";
            if (chkZJItems.Items[1].Selected == true)
                ajzpd += "2,";
            if (chkAJItems.Items[2].Selected == true)
                ajzpd += "0,";
            if (chkZJItems.Items[3].Selected == true)
                ajzpd += "3,";
            UpdateValue(ajzpd, "ZJ_ZPD");
            ajzpd = "";


            if (rbtnZJSH.Items[0].Selected == true)
                ajzpd = "1";
            else if (rbtnZJSH.Items[1].Selected == true)
                ajzpd = "0";
            UpdateValue(ajzpd, "ZJ_SHZT");
            ajzpd = "";


            if (rbtnZJItem.Items[0].Selected == true)
                ajzpd = "1";
            else if (rbtnZJItem.Items[1].Selected == true)
                ajzpd = "0";
            UpdateValue(ajzpd, "ZJ_SH");
            ajzpd = "";
        }    
       protected void BindSelectedAJ()
        { 
         if(SelectValue("AJ_ZPDZT")=="1")
         rbtnAJZPD.Items[0].Selected = true;  
         else if(SelectValue("AJ_ZPDZT")=="0")
         rbtnAJZPD.Items[1].Selected = true;
         
         string[]zpd = SelectValue("AJ_ZPD").Split(new char[] {','});
         for (int i = 0; i < zpd.Length; i++)
         { if (zpd[i] != "")
             {  if(zpd[i]=="1")
                chkAJItems.Items[0].Selected = true;
                if(zpd[i]=="2")
                chkAJItems.Items[1].Selected = true;
                if(zpd[i]=="0")
                chkAJItems.Items[2].Selected = true;
                if(zpd[i]=="3")
                chkAJItems.Items[3].Selected = true;
             }
         }

         if(SelectValue("AJ_SHZT")=="1")
         rbtnAJSH.Items[0].Selected = true;
         if (SelectValue("AJ_SHZT") == "0")
         rbtnAJSH.Items[1].Selected = true;
         
         if (SelectValue("AJ_SH") == "1")
         rbtnAJItem.Items[0].Selected = true;
         if (SelectValue("AJ_SH") == "0")
         rbtnAJItem.Items[1].Selected = true;
        }
       protected void BindSelectedZJ()
        {

            if (SelectValue("ZJ_ZPDZT") == "1")
                rbtnZJZPD.Items[0].Selected = true;
            else if (SelectValue("ZJ_ZPDZT") == "0")
                rbtnZJZPD.Items[1].Selected = true;

            string[] zpd = SelectValue("ZJ_ZPD").Split(new char[] { ',' });
            for (int i = 0; i < zpd.Length; i++)
            {
                if (zpd[i] != "")
                {
                    if (zpd[i] == "1")
                        chkZJItems.Items[0].Selected = true;
                    if (zpd[i] == "2")
                        chkZJItems.Items[1].Selected = true;
                    if (zpd[i] == "0")
                        chkZJItems.Items[2].Selected = true;
                    if (zpd[i] == "3")
                        chkZJItems.Items[3].Selected = true;
                }
            }

            if (SelectValue("ZJ_SHZT") == "1")
                rbtnZJSH.Items[0].Selected = true;
            if (SelectValue("ZJ_SHZT") == "0")
                rbtnZJSH.Items[1].Selected = true;

            if (SelectValue("ZJ_SH") == "1")
                rbtnZJItem.Items[0].Selected = true;
            if (SelectValue("ZJ_SH") == "0")
                rbtnZJItem.Items[1].Selected = true;
        
        
        
        
        }
       public static string SelectValue(string value)
        {   string key="";
            CONST_DEFINE_WEB_BLL bll = new CONST_DEFINE_WEB_BLL();
            var definebll=bll.GetModelList("Name= '"+value+"'");
            for (int i = 0; i < definebll.Length; i++)
            {key = definebll[i].ValueOfName;}
            return key;
         }
       protected void UpdateValue(string value, string key)
        {   CONST_DEFINE_WEB_BLL bll = new CONST_DEFINE_WEB_BLL();
            CONST_DEFINE_WEB model=new CONST_DEFINE_WEB();
            model.ValueOfName = value;
            bll.UpdateRange(model,"Name='"+key+"'");   
        }
       protected void rbtnAJSH_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (rbtnAJSH.Items[1].Selected == true)
            //{
            //    rbtnAJItem.Visible = false;

            //}
            //if (rbtnAJSH.Items[0].Selected == true)
            //{
            //    rbtnAJItem.Visible = true;

            //}
        }
       protected void rbtnAJZPD_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (rbtnAJZPD.Items[1].Selected == true)
            //{
            //    chkAJItems.Visible = false;

            //}
            //if (rbtnAJZPD.Items[0].Selected == true)
            //{
            //    chkAJItems.Visible = true;

            //}

        }     

    }
}